package com.sso.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;


@Configuration
public class TokenConfig {

    /**
     * 定义令牌存储方案, 本次选择基于jwt令牌方式存储用户状态
     * @return
     */
    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    /**
     * 配置jwt 令牌创建和解析对象
     * @return
     */
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
        JwtAccessTokenConverter Converter = new JwtAccessTokenConverter();
        Converter.setSigningKey(SIGNING_KEY);
        return Converter;
    }

    //这里的签名key将来可以写到配置中心
    private static final String SIGNING_KEY = "auth";
}
